@extends('admin.public')

@section('content')
    <div class="col-md-12">
        <form data-validate="parsley" method="post">
            <input type="hidden" name="id" value="{{ $chunk->id }}">
            {!! csrf_field() !!}
            <section class="panel panel-default">
                <header class="panel-heading">
                    {{ $frame['title'] }}
                    <a href="{{ route('admin.chunk.chunk') }}" class="btn btn-xs btn-default pull-right">信息模块</a>
                </header>
                <div class="panel-body">
                    <p class="text-muted">
                        如需设置模块模版页面,请前往文件夹:<span
                                class="text-info">{{ pathinfo(config('app.chunk_theme'))['dirname'] }}</span>,按指定格式(<span
                                class="text-info">{{ pathinfo(config('app.chunk_theme'))['basename'] }}</span>)添加模版文件!
                    </p>
                    <div class="form-group pull-in clearfix">
                        <div class="col-sm-6">
                            <label>模块名称</label>
                            <input type="text" class="form-control parsley-validated" data-required="true" name="name"
                                   placeholder="请填写模块名称" value="{{ $chunk->name }}">
                        </div>
                        <div class="col-sm-6">
                            <label>模块标识</label>
                            <input type="text" class="form-control parsley-validated" data-required="true" name="path"
                                   placeholder="模块标识" value="{{ $chunk->path }}">
                        </div>
                    </div>
                    <div class="form-group pull-in clearfix">
                        <div class="col-sm-6">
                            <label>分页数量
                                <small class="text-small">(请将数量控制在1-99之前)</small>
                            </label>
                            <div class="input-group m-b">
                                <input type="number" class="form-control parsley-validated" data-required="true" min="1"
                                       max="99"
                                       name="paginate" value="{{ $chunk->paginate }}" placeholder="请填写分页数量">
                                <span class="input-group-addon">条/页</span>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <label>相关信息数量
                                <small class="text-small">(请将数量控制在1-9之前)</small>
                            </label>
                            <div class="input-group m-b">
                                <input type="number" class="form-control parsley-validated" min="1" max="9"
                                       data-required="true"
                                       name="link_info_num" value="{{ $chunk->link_info_num }}" placeholder="请填写相关信息数量">
                                <span class="input-group-addon">条</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group pull-in clearfix">
                        <div class="col-sm-4">
                            <label>模块模版</label>
                            <div class="clearfix"></div>
                            <select style="width:100%" class="chosen-select" name="theme">
                                @foreach( $chunkThemes as $theme )
                                    <option value="{{ $theme }}" {{ $theme==$chunk->theme?'selected':'' }}>{{ $theme }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-sm-4">
                            <label>分类默认模版</label>
                            <div class="clearfix"></div>
                            <select style="width:100%" class="chosen-select" name="sort_theme">
                                @foreach( $sortThemes as $theme )
                                    <option value="{{ $theme }}" {{ $theme==$chunk->sort_theme?'selected':'' }}>{{ $theme }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-sm-4">
                            <label>信息默认模版</label>
                            <div class="clearfix"></div>
                            <select style="width:100%" class="chosen-select" name="info_theme">
                                @foreach( $infoThemes as $theme )
                                    <option value="{{ $theme }}" {{ $theme==$chunk->info_theme?'selected':'' }}>{{ $theme }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="form-group pull-in clearfix">
                        <div class="col-sm-6">
                            <label>拓展功能</label>
                            <div class="clearfix"></div>
                            <select style="width:100%" multiple class="chosen-select srcinfofield">
                                @foreach( $infoFields as $id => $name)
                                    <option value="{{ $id}}" {{ $chunk->info_fields && array_search($id,$chunk->info_fields)!==false?'selected':'' }}>{{ $name }}</option>
                                @endforeach
                            </select>
                            <input type="hidden" name="infofield" value="">
                        </div>
                        <div class="col-sm-6">
                            <label>拓展信息</label>
                            <div class="clearfix"></div>
                            <input name="extend" id="tagsinput_web_keywords_long" class="tagsinput"
                                   type="text" value="{{ $chunk->extend }}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>摘要信息</label>
                        <textarea class="form-control" name="simpledescribe"
                                  placeholder="企业信息摘要 (如未填写,则引用详细信息中的前部分信息)">{{ $chunk->simpledescribe }}</textarea>
                    </div>
                    <div class="form-group">
                        <label>详细信息</label>
                        <div id="describe" name="describe" type="text/plain" style="width: 100%;height: 300px;"></div>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="user_write" {{ (bool)$chunk->user_write?'checked':'' }}
                            class="parsley-validated"><i></i> 勾选此项,即开启全部账号 添加/编辑/删除 权限
                            <small class="text-danger">( 注册用户只可编辑/删除自己添加的信息! )</small>
                        </label>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="long_tail" {{ (bool)$chunk->long_tail?'checked':'' }}
                            class="parsley-validated"><i></i> 勾选此项,即开启信息长尾词匹配
                        </label>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="status" {{ (bool)$chunk->status?'checked':'' }}
                            class="parsley-validated"><i></i> 勾选此项,即开启此模块
                        </label>
                    </div>
                </div>
                <footer class="panel-footer text-right bg-light lter">
                    <button type="submit" class="btn btn-success btn-s-xs gatherInfo">保存</button>
                </footer>
            </section>
        </form>
    </div>
@endsection

@section('css')
    <link rel="stylesheet" href="/public/theme/js/chosen/chosen.css" type="text/css"/>
    <link rel="stylesheet" href="/public/theme/js/slider/slider.css" type="text/css"/>
@endsection

@section('js')
    <!-- slider -->
    <script src="/public/theme/js/slider/bootstrap-slider.js"></script>
    <!-- uediter -->
    <script src="/public/laravel-u-editor/ueditor.config.js"></script>
    <script src="/public/laravel-u-editor/ueditor.all.min.js"></script>
    <script src="/public/laravel-u-editor/lang/zh-cn/zh-cn.js"></script>
    <!-- Chosen -->
    <script src="/public/theme/js/chosen/chosen.jquery.min.js"></script>
    <!-- parsley -->
    <script src="/public/theme/js/parsley/parsley.min.js"></script>
    <script src="/public/theme/js/parsley/parsley.extend.js"></script>
    <!-- tagsinput -->
    <script src="/public/theme/js/tagsinput/bootstrap-switch.js"></script>
    <script src="/public/theme/js/tagsinput/jquery.tagsinput.js"></script>
    <script src="/public/theme/js/tagsinput/form-component.js"></script>
    <script type="text/javascript">
        $('.gatherInfo').click(function () {
            var need = '';
            $('a.search-choice-close').each(function () {
                var order = $(this).attr('data-option-array-index');
                var id = $('.srcinfofield').find('option:eq(' + order + ')').val();
                need += id + ',';
            })
            $('input[name="infofield"]').val(need);
        });
    </script>
    <script>
        var ue = UE.getEditor('describe');
        ue.ready(function () {
            var content = {'data': {!! json_encode($chunk->describe) !!}}
            ue.setContent(content.data);
        })
    </script>
@endsection